/**
 *
 */
package com.huilian.security.core.code.sms;


import com.huilian.security.core.code.ValidateCode;
import com.huilian.security.core.code.impl.AbstractValidateCodeProcessor;
import com.huilian.security.core.properties.SecurityConstants;
import com.huilian.security.sms.SmsCodeSender;
import com.huilian.security.sms.impl.SMSConfig;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;


/**
 * 短信验证码处理器
 *
 * @author: 少凡
 * @Date 2018/1/25
 */
@Component("smsValidateCodeProcessor")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    /**
     * 短信验证码发送器
     */
    @Resource
    private SmsCodeSender smsCodeSender;

    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
        smsCodeSender.send(mobile, validateCode.getCode(), SMSConfig.TEMPLATE_ID_VERIFY);
    }

}
